 package test;

import static org.junit.Assert.*;

import java.util.ArrayList;

import main.*;
import movement.Location;

import org.junit.Before;
import org.junit.Test;

import dispatch.DispatchCenter;
import emergency.*;

public class useCaseTestCreateDisaster {
	FacadeOperator facade;
	DispatchCenter center;

	Emergency em1, em2, dis;
	ArrayList<Emergency> emerg = new ArrayList<Emergency>();
	
	@Before
	public void setUp() throws Exception {
		String args[] = new String[1];
		args[0] = "environment.dat";
		World world = new World(args);
		
		facade = new FacadeOperator(world);
		center = facade.getDispatchCenter();
		
		em1 = new Robbery(new Location(10,10,"Robbery"), Severity.NORMAL, center, true, true);
		em2 = new TrafficAccident(new Location(30,30,"TrafficAcci"), Severity.SERIOUS, center, 2, 1);

		emerg.add(em1); emerg.add(em2);
	}
	
	@Test
	public void testCreateDisaster(){
		//default no disaster 
		assertEquals(center.getEmergenciesFromType("disaster").size(),0);
		
		//do behaviour like operator -> emerg has the selected emergencies
		facade.createDisaster("Gangs in NYE!", emerg);
		
		//check disaster added
		assertEquals(center.getEmergenciesFromType("disaster").size(),1);

		//check correctly set
		dis = center.getEmergenciesFromType("disaster").get(0);
		assertEquals("Gangs in NYE!",dis.getDescription());
		assertTrue(dis.getEmergenciesClone().contains(em1));
		assertTrue(dis.getEmergenciesClone().contains(em2));
		assertEquals(20,dis.getLocation().getX());
		assertEquals(20,dis.getLocation().getY());
		assertEquals(Severity.SERIOUS, dis.getSeverity());
		assertEquals(dis.getEmergencyPolicyString(), "Default Emergencypolicy");
		assertEquals(dis.getEmergenciesClone(),emerg);
		assertEquals(dis, em1.getDisaster());
		assertEquals(dis, em2.getDisaster());
		
		//disaster correctly created if all tests succeed	
	}
	
	@Test (expected = IllegalArgumentException.class)
	public void testCreateDisasterWithoutEmergencies(){
		//an disaster with no emergency won't be added to the dispatchcenter
		emerg = new ArrayList<Emergency>();
		facade.createDisaster("EmptyDisaster", emerg);
	}
}
